package com.example.financeapi.entity.vo;

import com.example.financeapi.enums.ResultEnum;
import lombok.Getter;

import java.io.Serializable;

/**
 * 自定义异常(统一异常返回)
 * @author Alvin
 */
@Getter
public class ResultException extends Exception implements Serializable {
    private static final long serialVersionUID = 1L;

    /**状态码*/
    private int code;
    /**异常信息*/
    private String msg;

    //无参构造
    public ResultException() {

    }

    //构造函数
    public ResultException(ResultEnum resultEnum) {
        super(resultEnum.getMessage());
        this.code = resultEnum.getCode();
    }

    //构造函数
    public ResultException(Integer code, String message) {
        super(message);
        this.code = code;
    }

    public ResultException(ResultEnum programException, String errorMsg) {
        super(programException.getMessage());
        this.code = programException.getCode();
    }

    public ResultException(ResultEnum programException, Object errorMsg) {
        this.msg=errorMsg.toString();
        this.code = programException.getCode();
    }

    //设置状态码
    public void setCode(Integer code) {
        this.code = code;
    }
}
